<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" th:src="@{/static/js/html5.js}"></script>
    <script type="text/javascript" th:src="@{/static/js/respond.min.js}"></script>
    <script type="text/javascript" th:src="@{/static/lib/PIE-2.0beta1/PIE_IE678.js}"></script>
    <![endif]-->
    <link th:href="@{/static/lib/layui/css/layui.css}" rel="stylesheet" type="text/css"/>
    <link th:href="@{/static/css/jx-admin.css}" rel="stylesheet" type="text/css"/>
    <link th:href="@{/static/lib/jx-fonts/iconfont.css}" rel="stylesheet" type="text/css"/>

    <script type="text/javascript" th:src="@{/static/lib/jquery/1.9.1/jquery.min.js}"></script>
    <script type="text/javascript" th:src="@{/static/lib/layui/layui.all.js}"></script><!--弹出框插件-->
    <script type="text/javascript" th:src="@{/static/js/jx.js}"></script>
    <script type="text/javascript" th:src="@{/static/js/jx-admin.js}"></script>

    <link th:href="@{/static/lib/layui/css/layui.css}" rel="stylesheet" type="text/css"/>
    <link th:href="@{/static/css/jx.css}" rel="stylesheet" type="text/css"/>
    <link th:href="@{/static/css/jx-admin.css}" rel="stylesheet" type="text/css"/>
    <link th:href="@{/static/lib/jx-fonts/iconfont.css}" rel="stylesheet" type="text/css"/>

    <title>编辑路由</title>
    <style type="text/css">
        .layui-form-label {
            float: left;
            display: block;
            width: 120px;
            font-weight: 400;
            line-height: 20px;
            text-align: right;
            padding: 9px 15px;
        }
        /*.layui-unselect dl {
            max-height:200px;
        }*/
        .layui-form-item .layui-input-inline {
            width: 290px;
        }
    </style>
</head>
<body>
<div class="x-body">
    <form class="layui-form jx_form" id="inputForm">
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">* </span>名称：
            </label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" autocomplete="off" name="name" id="name" required="" placeholder="名称">
            </div>
            <div class="layui-form-mid layui-word-aux">唯一标志， 不允许重复</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">* </span>path：
            </label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" autocomplete="off" name="path" id="path" required="" placeholder="请求路径">
            </div>
            <div class="layui-form-mid layui-word-aux">以 / 为前缀</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">* </span>调用地址：
            </label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" autocomplete="off" name="uri" id="uri" required="" placeholder="调用地址">
            </div>
            <div class="layui-form-mid layui-word-aux">负载使用 lb:// 前缀； 否则使用 http:// 前缀</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">* </span>顺序：
            </label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" autocomplete="off" name="orders" id="orders" value="0" required="" isInteger="true" placeholder="执行顺序">
            </div>
            <div class="layui-form-mid layui-word-aux">数值越小，优先级越高，默认0</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                Hystrix：
            </label>
            <div class="layui-input-inline" style="line-height: 38px; width: 80px;">
                <input type="checkbox" name="enableHystrix" lay-skin="switch" lay-text="ON|OFF">
            </div>
            <div class="layui-input-inline" style="width: 150px;">
                <input type="text" class="layui-input" autocomplete="off" name="hystrixValue" id="hystrixValue" isInteger="true" value="5000" placeholder="超时时间，单位ms" readonly>
            </div>
            <div class="layui-form-mid layui-word-aux">网关服务超时时间，默认5000</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                Log：
            </label>
            <div class="layui-input-inline" style="line-height: 38px; width: 80px;">
                <input type="checkbox" name="enableLog" lay-skin="switch" lay-text="ON|OFF">
            </div>
            <div class="layui-form-mid layui-word-aux">接口调用日志、响应时长记录</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                谓词：
            </label>
            <!--<div class="layui-input-inline">
                <input type="text" class="layui-input" autocomplete="off" name="predicate" id="predicate" placeholder="谓词">
            </div>-->
            <div class="layui-form-mid layui-word-aux">目前只支持Path方式，其他方式待扩展</div>
        </div>
    </form>
    <div class="layui-form-item jx_form_button" style="padding-left: 305px;">
        <button type="button" id="saveBtn" value="保 存" class="layui-btn"><i class="iconfont">&#xe601;</i>保 存</button>
        <button type="button" id="backBnt" value="返 回" class="layui-btn ml-50"><i class="iconfont">&#xe6ff;</i>返 回</button>
    </div>
</div>

<script type="text/javascript" th:src="@{/static/lib/jquery/1.9.1/jquery.min.js}"></script>
<script type="text/javascript" th:src="@{/static/lib/layui/layui.all.js}"></script>
<script type="text/javascript" th:src="@{/static/js/jx-admin.js}"></script>
<script type="text/javascript" th:src="@{/static/js/md5.min.js}"></script>
<script type="text/javascript" th:src="@{/static/js/jx.js}"></script>
<script type="text/javascript" th:src="@{/static/lib/jquery.form/jquery.form.js}"></script>
<script type="text/javascript" th:src="@{/static/lib/Validform/5.3.2/Validform.js}"></script>
<script type="text/javascript" th:src="@{/static/lib/jquery.validation/1.14.0/jquery.validate.min.js}"></script>
<script type="text/javascript" th:src="@{/static/lib/jquery.validation/1.14.0/validate-methods.js}"></script>
<script type="text/javascript" th:src="@{/static/lib/jquery.validation/1.14.0/messages_zh.min.js}"></script>

<script>
    layui.use(['form'], function() {
        var form = layui.form;
        form.on('select(startYear)', function(data){
            var endYear = parseInt(data.value) + 1;
            $("#endYear").val(endYear);
        });
    });

    $(window).load(function() {
        $("#backBnt").click(function(){
            layer_close();
        });
    });

    function validform(){
        /*返回一个validate对象，这个对象有一个form方法，返回的是是否通过验证*/
        return $("#inputForm").validate();
    }

    var alert_index;
    var options = {
        url: '[[@{/gateway/route/add}]]',
        type:"post",
        success: function (data) {
            if (data.success) {
                parent.layer.msg("保存成功！",{icon:1,time:2000});
                layer.close(alert_index);
                layer_close();
                x_admin_father_reload();
            } else {
                layer.msg(data.msg,{icon:2,time:2000});
                layer.close(alert_index);
            }
        }
    };

    $("#saveBtn").click(function () {
        if(validateSelect() && validform().form()) {
            alert_index = layer.load(3, {
                shade: [0.6,'#fff'] //0.6透明度的白色背景
            });
            $("#inputForm").ajaxSubmit(options);
        }
    });

</script>
</body>
</html>